import { makeAutoObservable } from 'mobx'
import { getBarriers, getBarriersNext, getBarriersLast, getBarriersMalan, getBarriersNextMalan, getBarriersLastMalan } from './api'
import type { BarriersListType } from './interface'
class Store {
    barriersList: BarriersListType = {
        id: '',
        type: '',
        scene_id: '',
        name: '',
        detail: [],
        next_id: '',
        last_id: '',
    }

    // 马兰花token
    token_malan = ''

    constructor() {
        makeAutoObservable(this)
    }

    async getBarriers(authToken: string) {
        if (authToken) {
            const { data } = await getBarriersMalan(authToken)
            this.barriersList = data as BarriersListType
            this.token_malan = authToken
        } else {
            const { data } = await getBarriers()
            this.barriersList = data as BarriersListType
        }
    }
    async getBarriersNextData(id: string) {
        if (!id) return
        if (this.token_malan !== '') {
            const { data } = await getBarriersNextMalan(id, this.token_malan)
            this.barriersList = data as BarriersListType
        } else {
            const { data } = await getBarriersNext(id)
            this.barriersList = data as BarriersListType
        }
    }
    async getBarriersLastData(id: string) {
        if (!id) return
        if (this.token_malan !== '') {
            const { data } = await getBarriersLastMalan(id, this.token_malan)
            this.barriersList = data as BarriersListType
        } else {
            const { data } = await getBarriersLast(id)
            this.barriersList = data as BarriersListType
        }
    }
}
export default Store
